package com.markerhub.application.service;

import cn.hutool.core.collection.CollectionUtil;
import com.markerhub.entity.TDeviceData;
import com.markerhub.entity.TUnusualPerson;
import com.markerhub.service.ITDeviceDataService;
import com.markerhub.service.ITUnusualPersonService;
import com.markerhub.vo.response.PersonInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @description:
 * @projectName: vueadmin-java
 * @author: zhouhaizhi
 * @createTime: 2021/9/22 14:02
 * @version:1.0
 */
@Service
public class QueryPersonInfoService {

    @Autowired
    private ITDeviceDataService itDeviceDataService;

    @Autowired
    private ITUnusualPersonService itUnusualPersonService;

    /***
     * 获取人员信息
     * @return
     */
    public List<PersonInfoVO> queryPersonInfo(int size) {
        List<PersonInfoVO> list = CollectionUtil.newArrayList();

        List<TDeviceData> deviceDatas = itDeviceDataService.queryNewestDataList(size);
        if (CollectionUtil.isNotEmpty(deviceDatas)) {
            for (TDeviceData deviceData : deviceDatas) {
                PersonInfoVO personInfoVO = new PersonInfoVO();
                TUnusualPerson tUnusualPerson = itUnusualPersonService.queryTUnusualPersonByImsi(deviceData.getImsi());
                personInfoVO.setImsi(deviceData.getImsi());
                if (null != tUnusualPerson) {
                    personInfoVO.setName(tUnusualPerson.getName());
                    personInfoVO.setMobile(tUnusualPerson.getMobile());
                    personInfoVO.setCardId(tUnusualPerson.getCardId());
                    personInfoVO.setHealthcodeState(tUnusualPerson.getHealthcodeState());
                    personInfoVO.setAcidtestTime(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(tUnusualPerson.getAcidtestTime()));
                    personInfoVO.setAcidtestResult(tUnusualPerson.getAcidtestResult());
                    personInfoVO.setHodometer(tUnusualPerson.getHodometer());
                    personInfoVO.setVaccination(tUnusualPerson.getVaccination());
                }
                list.add(personInfoVO);
            }
        }
        if(CollectionUtil.isNotEmpty(list)){
            for (PersonInfoVO personInfoVO : list){
                personInfoVO.setImsi(personInfoVO.getImsi()==null? null:personInfoVO.getImsi().replaceAll("(\\d{5})\\d{5}(\\d{5})", "$1****$2"));
            }
        }

        return list;
    }
}
